package com.wocao.admin.controller;

import com.wocao.admin.business.SysUserBusiness;
import com.wocao.commom.result.Result;
import com.wocao.system.entity.vo.user.SysUserAddVo;
import com.wocao.system.entity.vo.user.SysUserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户控制类
 *
 * @author sunhao
 * @date 2021/8/13
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@RestController
@Slf4j
@Api(tags = "用户文档")
@RequestMapping("/sys/user")
public class SysUserController {

    @Autowired
    private SysUserBusiness sysUserBusiness;

    /**
     * 功能描述: 根据用户名查询用户信息<br>
     *
     * @param userName 用户名称
     * @return com.dpl.iot.common.result.Result<com.dpl.iot.admin.entity.SysUserVo>
     * @author 翟思权 2021-08-27 15:06
     * @see [相关类/方法]（可选）
     * @since [产品/模块版本]（可选）
     */
    @ApiOperation(value = "根据用户名查询用户信息", notes = "根据用户名查询用户信息")
    @ApiImplicitParam(name = "userName", value = "用户名", dataType = "String", required = true)
    @GetMapping(value = "/getSysUserByUserName")
    public Result<SysUserVo> getSysUserByUserName(String userName) {
        try {
            SysUserVo sysUser = sysUserBusiness.getSysUserByUserName(userName);
            return Result.SUEECSS(sysUser, "查询成功！");
        } catch (Exception e) {
            log.error("SysUserController.getSysUserByUserName is error, userName={}", userName, e);
        }
        return Result.ERROR("查询失败！");
    }

    /**
     * 功能描述: 添加用户信息<br>
     *
     * @param sysUserAddVo 用户添加实体
     * @return com.dpl.iot.common.result.Result<java.lang.String>
     * @author 翟思权 2021-08-27 15:06
     * @see [相关类/方法]（可选）
     * @since [产品/模块版本]（可选）
     */
    @ApiOperation(value = "添加用户信息", notes = "添加用户信息")
    @GetMapping(value = "/addUser")
    public Result<String> addUser(@RequestBody SysUserAddVo sysUserAddVo) {
        try {
            sysUserBusiness.addUser(sysUserAddVo);
            return Result.SUEECSS("添加成功!");
        } catch (Exception e) {
            log.error("SysUserController.addUser is error,sysUserAddVo={}", sysUserAddVo, e);
        }
        return Result.ERROR("添加失败!");
    }

}
